/**
 * 
 */
package fr.gfi.agraf.vue.action.tableau;

import java.util.List;

import fr.gfi.agraf.service.ITdbService;
import fr.gfi.agraf.utils.SpringFactory;
import fr.gfi.agraf.vue.action.AbstractApplicationSupportAction;
import fr.gfi.agraf.vue.bean.PerimetreDTO;
import fr.gfi.agraf.vue.bean.TdbFrontEquipe;

/**
 * @author Fw
 * 
 */
public class VoirTdBEquipeAction extends AbstractApplicationSupportAction {

	/**
	 * Généré par Java
	 */
	private static final long serialVersionUID = -8135147066923018249L;

	private static final String TDB_SERVICE = "TdbService";

	private static final int LARGEUR_PIXEL_TAUX_AVANCEMENT = 300;

	private List<PerimetreDTO> listePerimetre;

	@Override
	public String executeAction() throws Exception {

		final ITdbService tdbService = (ITdbService) SpringFactory.getApplicationContext().getBean(
				TDB_SERVICE);

		final TdbFrontEquipe front = tdbService.getStatsForTdbEquipe();

		listePerimetre = front.getListePerimetre();

		return SUCCESS;
	}

	/**
	 * Renvoie les label pour le charts des barres
	 * 
	 * @return
	 */
	public String getLabelPerimetre() {
		final StringBuilder sb = new StringBuilder();
		int index = 0;
		for (final PerimetreDTO perimetreDTO : listePerimetre) {
			sb.append(perimetreDTO.getLibelle());
			if (index != listePerimetre.size() - 1) {
				sb.append("###");
			}
			index++;
		}
		return sb.toString();
	}

	/**
	 * renvoie la charge intiale de chaque perimetre pour le charts des barres
	 * 
	 * @return
	 */
	public String getChargeInitTotalToCharts() {
		final StringBuilder sb = new StringBuilder();
		int index = 0;
		for (final PerimetreDTO perimetreDTO : listePerimetre) {
			sb.append(perimetreDTO.getChargeInitTotale());
			if (index != listePerimetre.size() - 1) {
				sb.append("###");
			}
			index++;
		}
		return sb.toString();
	}

	/**
	 * renvoie le conso total de chaque perimetre pour le charts des barres
	 * 
	 * @return
	 */
	public String getConsoTotalToCharts() {
		final StringBuilder sb = new StringBuilder();
		int index = 0;
		for (final PerimetreDTO perimetreDTO : listePerimetre) {
			sb.append(perimetreDTO.getConsommeTotal());
			if (index != listePerimetre.size() - 1) {
				sb.append("###");
			}
			index++;
		}
		return sb.toString();
	}

	/**
	 * renvoie le conso total de chaque perimetre pour le charts des barres
	 * 
	 * @return
	 */
	public String getRafTotalToCharts() {
		final StringBuilder sb = new StringBuilder();
		int index = 0;
		for (final PerimetreDTO perimetreDTO : listePerimetre) {
			sb.append(perimetreDTO.getRafTotal());
			if (index != listePerimetre.size() - 1) {
				sb.append("###");
			}
			index++;
		}
		return sb.toString();
	}

	public int getLargeurTauxAvancement() {
		return LARGEUR_PIXEL_TAUX_AVANCEMENT;
	}

	/**
	 * @return the listePerimetre
	 */
	public List<PerimetreDTO> getListePerimetre() {
		return listePerimetre;
	}

}
